/**
 * Copyright (c) 2009 blurredVision
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
 * associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 
 * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#ifndef __MODEL_IMODELKFANIMATED_H__
#define __MODEL_IMODELKFANIMATED_H__

#pragma once

namespace model {

class IModelBase;

/**
 *  Control information for a keyframe animated model.
 *  This class extends the model information for IModelBase
 *  Animations inside the mesh are stored from frame 1 (beginning) to m_iMaxFrame
 */
class DLL_EXPORT IModelKFAnimated
{
public:
	/// Set the animation speed to the number of frames per second
	virtual void setAnimationSpeed(int framesPerSecond);

	/// Get the number of frames per second in the animation
	const int& getAnimationSpeed() const;

	/// Play a subset of the animation from startFrame to endFrame and set if the subset should be looped
	void play(int startFrame, int endFrame, bool loop = true);

	/// Play the whole keyframe animation from frame 1 to m_iMaxFrame
	void playAll(bool loop = true);

	/// Spring to a certain frame and stop the animation
	void gotoAndStop(int framenum);

	/// Return the number of frames inside the animation
	int getFrameCount() const;

	/// Get current frame
	const int getCurrentFrame() const;

protected:
	// Constructor is protected, so no instance can be created directly. Use IModelBase::Load to load model
	IModelKFAnimated();
	virtual ~IModelKFAnimated();

	/// Updates the keyframes for a given dt. Returns if the animation is paused
	bool updateKeyFrames(double dt);

	/// Loads the key frame data from the file
	bool loadKeyFrameData(FILE* file, IModelBase *base);

	int    m_iFPS;			///< The frames per second inside the animation. Default is 15
	double m_dCurrentFrame;	///< The double value for the current frame
	int    m_iMaxFrame;		///< The maximum frame that has a keyframe information
	
	int    m_iStartFrame;	///< The starting frame for a subset of the animation
	int    m_iEndFrame;		///< The ending frame for a subset of the animation
	bool   m_bLoop;			///< The loop flag for looping the animation
	bool   m_bStarted;		///< Indicates if the animation is started
};

} // namespace

#endif
